package com.zut.service.impl;

import com.aliyun.oss.OSS;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.io.InputStream;

@Service
public class OssService {
    private final OSS oss;

    @Autowired
    public OssService(OSS oss) {
        this.oss = oss;
    }

    //上传文件到oss
    public String uploadFileAvatar(MultipartFile file) throws Exception {
        String url = null;
        //获取上传文件 MultipartFile
        //返回图片在oss上的路径
        InputStream inputStream = file.getInputStream();
        String filename = file.getOriginalFilename();
        String uuid = java.util.UUID.randomUUID().toString();
        filename = uuid + filename;
        oss.putObject("ekko-pi", filename, inputStream);
        url = "https://ekko-pi.oss-cn-beijing.aliyuncs.com/" + filename;



        return url;
    }


    //下载文件


}


